package com.cyy.swiperefresh;

import android.graphics.Color;
import android.os.Handler;
import android.support.v4.widget.SwipeRefreshLayout;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.ListView;

import java.util.ArrayList;
import java.util.List;

public class MainActivity extends AppCompatActivity {
    private SwipeRefreshLayout swipeRefreshLayout;
    private ListView lv_fresh;
    private List<String> mDatas;
    private MyAdaptr adapter;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        mDatas = new ArrayList<>();
        lv_fresh = (ListView) findViewById(R.id.lv_fresh);
        swipeRefreshLayout = (SwipeRefreshLayout) findViewById(R.id.swipe_refresh);

        swipeRefreshLayout.setColorSchemeColors(Color.BLUE);
        swipeRefreshLayout.setProgressBackgroundColorSchemeColor(Color.GREEN);

        for (int i = 0; i <50 ; i++) {
            mDatas.add("mDatas:::"+i);
        }
        adapter = new MyAdaptr(this,mDatas);
        lv_fresh.setAdapter(adapter);


        swipeRefreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
            @Override
            public void onRefresh() {
                mHandler.postDelayed(new Runnable() {
                    @Override
                    public void run() {
                        //mDatas.clear();
                        for (int i = 0; i <20 ; i++) {
                            mDatas.add("刷新操作");
                            adapter.notifyDataSetChanged();
                            swipeRefreshLayout.setRefreshing(false);
                        }
                    }
                },300);
            }
        });
        //shishisisisiisisiisjfls
        //jijiji
    }
    Handler mHandler = new Handler();
}
